package org.jackysoft.struts2.business;

import java.util.Collection;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.Contract;
import org.jackysoft.entity.ContractClient;
import org.jackysoft.entity.ContractDataItem;
import org.jackysoft.entity.ContractItem;
import org.jackysoft.entity.Product;
import org.jackysoft.entity.ProductIncomeItem;
import org.jackysoft.service.ContractClientService;
import org.jackysoft.service.ContractService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Namespace("/contract")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class ContractAction extends UtilsCRUDAction<Contract> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 203569556990807314L;
	private ContractService service;
	private ContractClientService clientService;
	private Contract bean;
	private Collection<Contract> beans;
	private Collection<ContractClient> clients;
	private ContractDataItem detail ;
	private ContractItem item;		
	private ProductIncomeItem  income;
	private Collection<ProductIncomeItem> incomes;
	private ContractClient client;
	private Product product;
    private Integer year;
	
    
	
	@Override
	public String newEdit() throws Exception {
		
		clients = clientService.gets();
		this.query();
		return super.newEdit();
	}

	@Override
	public String input() throws Exception {	
		
		return super.input();
	}

	
	public String updatedataitem() throws Exception{
		
		service.updateDetail(detail);
		return "updatedataitem";		
	}
	
	public String updateitem() throws Exception{
		service.updateItem(item);
		return "updatedataitem";		
	}
	public String removeitem() throws Exception{
		service.removeItem(bean, item);
		return "updatedataitem";
		
	}
	
	public String submitrepo() throws Exception{
		service.submitLine(income);
		return "submited";
	}
	
	public String showsubmits() throws Exception{
		incomes = service.showSubmitLine(bean, item);
	    return "submits";
	}
	
	
	
	public String startturnin() throws Exception{
				
		return "startturnin";
	}
	
	public String myturnin() throws Exception{
		incomes = service.myIncomeItems(usedate);
		return "myturnin";
	}
	
	
	public String turnin() throws Exception{
		service.turnin(income);
		return "turnin";
	}
	
	public String contractsincode() throws Exception{
		
		beans = service.findContractsByCode(product);
		
		return "incode";
	}
	
	
	public String removeIncome() throws Exception{
		
		service.removeIncome(term);
	    return SUCCESS;
	    
	}
	
	@Override
	public String dataimport() throws Exception {		
		
		errorHtml = service.create(upLoad, getYear());	
		
		return "uploador";
	}

	
	
	public String byclient() throws Exception{
		beans = service.getsByClient(getClient());	
		return "byclient";
	}
	
	public String startquery() throws Exception{
		
		clients     = clientService.gets();		
		beans       = service.gets();
		stringList  = service.getContractNames();
		return "startquery";
	}
	
	public String collect() throws Exception{
		this.pager = this.service.collect(query);
		return query.getSqlId();
	}
	
	public String counterof() throws Exception{
	    int count = this.service.countByExpress(query);
	    resultMap.clear();
	    resultMap.put("counter", count);
	    return MAPDATA;
	}	

	public void setBean(Contract bean) {
		this.bean = bean;
	}

	public Contract getBean() {
		return this.bean;
	}

	public void setBeans(Collection<Contract> beans) {

		this.beans = beans;
	}

	public Collection<Contract> getBeans() {
		return this.beans;
	}

	@Resource
	public void setService(ContractService service) {
		this.service = service;
		this.setDataProvider(service);
	}

	public ContractService getService() {
		return this.service;
	}
	

	public Collection<ContractClient> getClients() {
		return clients;
	}

	public void setClients(Collection<ContractClient> clients) {
		this.clients = clients;
	}

	
	@Resource
	public void setClientService(ContractClientService clientService) {
		this.clientService = clientService;
	}

	public ContractDataItem getDetail() {
		return detail;
	}

	public void setDetail(ContractDataItem detail) {
		this.detail = detail;
	}

	public ContractItem getItem() {
		return item;
	}

	public void setItem(ContractItem item) {
		this.item = item;
	}

	public ProductIncomeItem getIncome() {
		return income;
	}

	public void setIncome(ProductIncomeItem income) {
		this.income = income;
	}

	public Collection<ProductIncomeItem> getIncomes() {
		return incomes;
	}

	public void setIncomes(Collection<ProductIncomeItem> incomes) {
		this.incomes = incomes;
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public ContractClient getClient() {
		return client;
	}

	public void setClient(ContractClient client) {
		this.client = client;
	}

	

}